package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.transformation.editor.model.AtomicTransformation;
import edu.pku.sei.transformation.editor.model.constraint.Constraint;

public class RuleStructureDiagramConstraintDeleteCommand extends Command {
	AtomicTransformation transformation;
	Constraint constraint;

	public RuleStructureDiagramConstraintDeleteCommand(
			AtomicTransformation transformation, Constraint constraint) {
		this.transformation = transformation;
		this.constraint = constraint;
	}

	@Override
	public boolean canExecute() {
		if (transformation != null && constraint != null)
			return true;
		else
			return false;
	}

	@Override
	public void undo() {
		constraint.setContainer(transformation);
		transformation.getConstraints().add(constraint);
	}

	@Override
	public void execute() {
		transformation.getConstraints().remove(constraint);
		constraint.setContainer(null);
	}

}
